from app.db.dbUserRolePower import rolePowerQuery


def permission_detect(endpoint, userRoleId):
    '''
    endpoint: Blueprint('xxxx').route
    '''
    endpoint = endpoint.split('.')[0]
    bAuthorization = False
    rolePower = rolePowerQuery(userRoleId)
    if rolePower is False: # 未找到该角色
        return bAuthorization, rolePower

    if len(rolePower) > 0:
        for v in rolePower:
            if endpoint in v:
                bAuthorization = True
                break

    return bAuthorization, rolePower